FROM alpine:3.12.0

# Install the necessary packages
RUN sed -i 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#' /etc/apk/repositories \
  && apk add dnsmasq wget nginx \
  && rm -rf /var/cache/apk/*

ENV SYSLINUX_VERSION 6.03
ENV TEMP_SYSLINUX_PATH /tmp/syslinux-"$SYSLINUX_VERSION"

ENV COREOS_VERSION 32.20200715.3.0
ENV TEMP_COREOS_PATH /tmp/coreos-"$COREOS_VERSION"


WORKDIR /tmp

RUN mkdir -p "$TEMP_SYSLINUX_PATH" \
  # wget -q https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-"$SYSLINUX_VERSION".tar.gz \
  && wget -q http://sh.hc-yun.com:32050/data/syslinux-"$SYSLINUX_VERSION".tar.gz \
  && tar -xzf syslinux-"$SYSLINUX_VERSION".tar.gz \
  && mkdir -p /var/lib/tftpboot \
  && cp "$TEMP_SYSLINUX_PATH"/bios/core/pxelinux.0 /var/lib/tftpboot/ \
  && cp "$TEMP_SYSLINUX_PATH"/bios/com32/libutil/libutil.c32 /var/lib/tftpboot/ \
  && cp "$TEMP_SYSLINUX_PATH"/bios/com32/elflink/ldlinux/ldlinux.c32 /var/lib/tftpboot/ \
  && cp "$TEMP_SYSLINUX_PATH"/bios/com32/menu/menu.c32 /var/lib/tftpboot/ \
  && rm -rf "$TEMP_SYSLINUX_PATH" \
  && rm /tmp/syslinux-"$SYSLINUX_VERSION".tar.gz 

RUN cd /var/lib/tftpboot \
  && wget -q https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/images/pxeboot/initrd.img \
  && wget -q https://mirrors.aliyun.com/centos/7.8.2003/os/x86_64/images/pxeboot/vmlinuz 

# Configure DNSMASQ
COPY etc/ /etc
COPY entpoint.sh /entpoint.sh
COPY pxelinux.cfg/default /var/lib/tftpboot/pxelinux.cfg/default

# Start dnsmasq. It picks up default configuration from /etc/dnsmasq.conf and
# /etc/default/dnsmasq plus any command line switch
ENTRYPOINT ["/entpoint.sh"]

CMD ["--dhcp-range=172.18.0.50,172.18.0.99,255.255.255.0,24h"]
